<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../../css/aui.css">
    <link rel="stylesheet" type="text/css" href="../../css/aui-slide.css">
    <link rel="stylesheet" type="text/css" href="../../css/api.css">
    <link rel="stylesheet" type="text/css" href="../../font-icon/demo.css">
    <link rel="stylesheet" type="text/css" href="../../font-icon/iconfont.css">
    <script type="text/javascript" src="../../script/api.js"></script>
</head>
<body >
    <div class="fixed">
        <header class="monopoly" id="header">
            <div class="top3">品牌直销馆</div>
            <div class="top4" tapmode onclick="api.closeWin();">活色生鲜馆</div>
            <div class="top5" >
                <ul>
                    <li tamnode onclick="drop_down();">分类&nbsp;∨</li>
                    <ul id="list_p" style="display:none">
                        <li onclick="api.closeWin();">化妆</li>
                        <li onclick="baojian();">保健</li>
                        <!-- <li>瑞尔姿</li>
                        <li>纽崔莱</li>
                        <li>雅姿</li>
                        <li>玛丽艳</li> -->
                    </ul>
                </ul>
            </div>
        </header>
    </div>
    <div class="listContent" id="goodslist">
    </div>
    <div class="aui-card-list-footer aui-text-center" id="refresh" style="display:none;">
        <span>下拉加载更多</span>
    </div>
</body>
<!-- <script type="text/javascript" src="../../script/youquan.js"></script> -->
<!-- <script type="text/javascript" src="../../script/common.js"></script> -->
<script type="text/javascript">
    // const URL = "http://www.samlion.com/goodsapi.php?app=7";
    var uid =  $api.getStorage('uid')
    apiready = function() {  
    var arr = new Array;
    var arr1 = new Array;
    var URL = api.pageParam.url;
    alert(URL);
    window.openGoods = function(i) {
        const url = 'http://www.samlion.com/mobile/goods.php?id=' + arr[i]+ 'name=' + uid
        api.openWin({
            name: 'formwork',
            url: '../main/mZhuang.html',
            pageParam: {
                url: url,
                // id: arr1[i],
                // token: token
            },
        });
    }
    
    if (length != '') {
        $api.byId('refresh').style = "display:block";
        api.addEventListener({
            name: 'scrolltobottom'
        }, function(ret, err) {

            var body = {
                code: 'jiu',
                token: $api.getStorage('token'),
                j: j++
            }
            // alert(body)
            api.ajax({
                url: URL,
                method: 'get',
                dataType: 'json',
                "headers": {
                    "Content-Type": "application/json"
                },
                // data: {
                //     body: body
                // }
            }, function(ret, err) {
                showGoods();
            });

        });
    } else {
        $api.byId('refresh').style = "display:none";
    }
    // alert(JSON.stringify(body));
    showGoods();

    function showGoods() {
        api.ajax({
            url: URL,
            method: 'get',
            dataType: 'json',
            "headers": {
                "Content-Type": "application/json"
            },
            // data: {
            //     body: body
            // }
        },
        function(ret, err) {
            // alert(JSON.stringify(ret));
            if (ret) {
                length = ret.length;
                $api.byId('goodslist').innerHTML = '';
                for (var i = 0; i < ret.length; i++) {
                    var rand = Math.floor(Math.random () * 2000) + 100;
                    data = ret[i];
                    arr.push(data.id);
                    arr1.push(data.id);
                    token = data.token;

                    $api.byId('goodslist').innerHTML +=
                        '<ul class="aui-list aui-media-list" ;">' +
                        '<li class="aui-list-item">' +
                        '<div class="aui-media-list-item-inner">' +
                        '<div class="aui-list-item-media">' +
                        '<img src="http://www.samlion.com/' + data.img + '">' +
                        '</div>' +
                        '<div class="aui-list-item-inner">' +
                        '<div class="aui-list-item-text">' +
                        '<div class="aui-list-item-title">' + data.title + '</div>' +
                        '</div>' +
                        '<div class="aui-list-item-text">' +
                        '<div>已售：' + rand + '件&nbsp;&nbsp;&nbsp;&nbsp;<span class="aui-bg-pink" style="color:#fff;font-size:14px;">返利</span></div>' +
                        '</div>' +
                        '<div class="aui-list-item-text">' +
                        '<div><span style="color:red;font-size:20px;">￥' + data.discount_price + '</span>&nbsp; <span><s>￥' + data.price + '</s></span></div>' +
                        '</div>' +
                        '<div class="aui-list-item-text aui-pull-right">' +
                        '<a class="aui-info-item aui-btn aui-btn-warning "  onclick="openGoods(' + i + ');">去抢购</a></div></div></div></li></ul>';
                }
            } else {
                // alert(JSON.stringify(err));
            }
        });
    }

}
    // apiready = function() {
    //     var header = $api.byId('header');
    //     var headerPos = $api.offset(header);
    //     var uuid=api.pageParam.uuid;
    //     var u=api.pageParam.u;
    //     var search_inputVal=api.pageParam.search_inputVal;
    //     var footerPos =api.pageParam.footerPos;
    //     // var url = api.pageParam.url;
    //     api.openFrame({
    //         name: 'xiongshi',
    //         url: "http://www.samlion.com/mobile/category.php?id=362",
    //         rect: {
    //             x: 0,
    //             y: headerPos.h,
    //             w: 'auto',
    //             h: "auto",
    //         }
    //     });
    // }

    window.drop_down = function() {
        
        var drop = document.getElementById("list_p");
        // alert(drop.style.display);
        if(drop.style.display == "none") {
            $api.css(drop,"display:block;");
        }else{
            $api.css(drop,"display:none;");
        }
        // if(drop.style.display == "block") {
        //     $api.css(drop,"display:none;");
        // }
    }

    // window.shenghuo = function() {
    //             api.openWin({
    //                 name: 'youquanmian',
    //                 url: './youquanmian.html',
    //                 rect: {
    //                     x: 0,
    //                     y: 0,
    //                     w: 'auto',
    //                     h: 'auto'
    //                 },
    //                 allowEdit: true
    //             });
    // }

   
</script>

</html>
